<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	var that = null;
	export default {
		onLaunch: function() {
			that = this;
			let host = that.$config.hosts[0];
			that.setHost(host);
		
			if (that.globalData.netConnected) {
				if(uni.getStorageSync('login_atk')){
					that.loadUserInfo();
				}
			}
			if(uni.getSystemInfoSync().deviceType != 'phone'){	//非手机端禁止使用
				that.showAlert();
			}
		},
		
		computed: mapState(['hasLogin']),
		methods: {
			...mapMutations(['login', "setUserInfo", "setHost"]),
			
			showAlert(){
				that.$api.alert('请在手机端使用！',()=>{
					that.showAlert();
				})
			},
			
			loadUserInfo() {
				that.$http.get(that.$config.UrlUserInfo,{},{log:true}).then((res) => {
					if(res.code == 1){
						let userInfo = res.data || {};
						that.setUserInfo(res.data);
						that.$store.commit('login');
					}
				})
			},
		},
		globalData: {
			netConnected: true, //持有网络状态
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-ui/index.scss";
	@import "./static/font/iconfont.css"; //扩充字体
	@import "./common/layout.css"; //公共样式
</style>
